<template>
   <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px" size="medium">
      <!-- <el-form ref="form" :model="form" :rules="formRules" label-width="120px" size="medium"> -->
      <el-form-item label="员工姓名" prop="username">
        <el-input v-model="form.username" style="width:300px" />
      </el-form-item>
      <el-form-item label="员工工号" prop="workNum">
        <el-input v-model.trim="form.workNum" style="width:300px" @blur="testExist" disabled />
      </el-form-item>
      <el-form-item label="岗位类别" prop="jobCategory">
        <el-input v-model.trim="form.jobCategory" disabled style="width:300px" />
      </el-form-item>
      <el-form-item label="隶属工段" prop="sectionNo">
        <el-input v-model="form.sectionNo" style="width:300px" />
      </el-form-item>
      <el-form-item label="员工角色" prop="roleId">
        <el-select v-model="form.roleId" placeholder="请选择该员工当前角色" @focus="getRoleInfo" style="width:300px">
          <el-option :value="item.roleId" :label="item.roleName" v-for="(item,index) of this.roleList.data" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="form.roleIds" placeholder="请选择角色" style="width:300px">
            <el-option v-for="item in roleOptions" :key="item.roleId" :label="item.roleName" :value="item.roleId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="员工短号" prop="shortNum">
        <el-input v-model="form.shortNum" style="width:300px" />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input v-model="form.phone" maxlength="11" style="width:300px" />
      </el-form-item>
      <el-form-item label="隶属部门" prop="departmentName">
        <el-select v-model="form.departmentName" placeholder="请选择该员工当前所在部门" @focus="getDepartInfo" style="width:300px" @change="changesectionType">
          <el-option :value="item" :label="item" v-for="(item,index) in this.departList.data" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="归属部门" prop="deptId">
        <treeselect v-model="form.deptId" :options="enabledDeptOptions" :show-count="true" placeholder="请选择归属部门" style="width:300px"/>
      </el-form-item>
      <el-form-item label="组别" prop="sectionType" v-if="form.departmentName && this.isNeedget(this.form.departmentName)">
        <el-select v-model="form.sectionType" placeholder="组别" @focus="getsectionType" style="width:300px">
          <el-option :value="item" :label="item" v-for="(item,index) in this.sectionTypeList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="所在岗位" prop="jobTitle">
        <el-select v-model="form.jobTitle" placeholder="请选择所在岗位" style="width:300px" @change="changeJobTitle">
          <el-option :value="item.id" :label="item.jobTitle" v-for="(item) in this.jobTitleList" :key="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="岗位级别" prop="rankOfPosition">
        <el-input disabled v-model="form.rankOfPosition" style="width:300px" />
      </el-form-item>
      <el-form-item label="关键工序" prop="criticalProcessName">
        <el-input disabled v-model="form.criticalProcessName" style="width:300px" />
      </el-form-item>
      <!-- <el-form-item label="工种类型" prop="type" required v-if="form.departmentName == '数控车间'">
        <el-select v-model="form.type" placeholder="请选择该员工工种类型" style="width:300px">
          <el-option :value="item" :label="item" v-for="(item,index) of this.typeList" :key="index"/>
        </el-select>
      </el-form-item> -->
      <el-form-item label="上级领导工号" prop="parentNumber">
        <el-select
          filterable
          v-model="form.parentNumber"
          placeholder="请选择上级领导"
          style="width: 300px;"
          >
          <el-option
            v-for="item,index in userNameList"
            :key="index"
            :label="item.userName"
            :value="item.jobNumber"
          />
        </el-select>
        <!-- <el-input v-model="form.parentNumber" @blur="testExist2" style="width:300px" /> -->
      </el-form-item>
      <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker v-model="form.entryTime" editable format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width:300px" />
      </el-form-item>
      <el-form-item label="岗位技能" prop="jobTitle">
          <div v-for="(items,index1) in jobTitleList" :key="index1" style="margin-bottom: 5px;">
             <div style="display: inline-block; width: 100px;">{{ items.jobTitle ? items.jobTitle : '无' }}</div>
            {{' 技能等级: '}}
            <div style="display: inline-block; width: 80px;">{{ items.rankOfPosition ? items.rankOfPosition : '无' }}</div>
            {{' 关键工序: '}}
            <div style="display: inline-block;">{{ items.criticalProcessName ? items.criticalProcessName : '无'}}</div>
        </div>
      </el-form-item>
      <el-form-item label="邮箱" prop="mail" :rules="[
      { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
    ]">
        <el-input v-model="form.mail" style="width:300px" />
      </el-form-item>
      <el-form-item label="导师" prop="tutorUserName">
        <el-select filterable clearable v-model="form.tutorUserName" placeholder="请选择导师" @focus="focusName" @change="tutorChange" style="width:300px">
          <el-option :value="item.jobNumber" :label="item.userName" v-for="(item,index) of this.nameList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="新员工标识" prop="newEmployee">
        <el-switch v-model="form.newEmployee" active-value="1" inactive-value="0" active-text="新员工" inactive-text="老员工" />
      </el-form-item>
      <el-form-item label="启用状态" prop="status">
        <el-switch v-model="form.status" active-value="1" inactive-value="0" active-text="启用" inactive-text="停用" />
      </el-form-item>
      <el-form-item label="openID">
        <el-input v-model="form.openid" style="width:300px" :disabled='true'/>
      </el-form-item>
      <el-form-item label="员工头像上传">
        <el-upload
          class="avatar-uploader"
          action="https://www.golwayhhln.top/hnsMes/portraitUploadFile"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :data="upPictureData"
          :headers="upPictureHeader"
          :before-upload="beforeAvatarUpload">
          <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="modify">修改</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { parseTime,parseTimeYYDD,getTimeHMS } from '@/utils'
import { getList,addWorker,updateManager,updateIsFlag,updatePassword,getDepartment,getRoleList,getDepartList,testWorkNum,modifyWorkers } from '@/api/user'
import { checkWorkSecInfo } from '@/api/workSection.js'
import { findUserListGroup } from '@/api/chargingData.js'
import { deptTreeSelect,systemgetUser } from '@/api/dept.js'
import { validatePhone, validateChineseName, validateNum} from '@/utils/validate'
import mixin from '@/utils/mixin.js'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: 'updateData_List',
  mixins: [mixin],
  components: { Treeselect },
 data() {
    return {
      form: {
        username: '',
        sectionNo: '',
        roleId: '',
        workNum: '',
        shortNum: '',
        jobClassStr: '',
        openid: '8D4DD3F80CEB6149329FDBD590B164F1',
        parentNumber: '',
        phone: '',
        departmentName: '',
        sectionType: '',
        type: '',
        entryTime: '',
        mail:'', // 邮箱
        status: false,
        imageUrl: '',
        newEmployee: false,
        tutorUserName:'',
        roleIds:[]
      },
      // 接受来自list页面传过来的数据
      getItem: null,
      // 从级联选择器获取到的数据以对象的形式暂时存放在grade当中
      grade: [],
      departList: {},
      // 上传图片文件的头部
      upPictureHeader: { CHECK_USER_VALUE: 'GOLWAY', CHECK_PASSWORD_VALUE: '8D4DD3F80CEB6149329FDBD590B164F1' },
      // 上传上传图片文件的信息
      upPictureData: { jobNumber: '', file: '' },
      // 角色下拉列表信息
      roleList: {},
      selectDepart: [],
      // 岗位职级下拉选项
      options: [{
        value: 'O1',
        label: 'O1',
        children: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3',
          label: '3'
        }, {
          value: '4',
          label: '4'
        }, {
          value: '5',
          label: '5'
        }]
      }, {
        value: 'O2',
        label: 'O2',
        children: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3',
          label: '3'
        }, {
          value: '4',
          label: '4'
        }, {
          value: '5',
          label: '5'
        }]
      }, {
        value: 'O3',
        label: 'O3',
        children: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3',
          label: '3'
        }, {
          value: '4',
          label: '4'
        }, {
          value: '5',
          label: '5'
        }]
      },  {
        value: 'O4',
        label: 'O4',
        children: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3',
          label: '3'
        }, {
          value: '4',
          label: '4'
        }, {
          value: '5',
          label: '5'
        }]
      }, {
        value: 'O5',
        label: 'O5',
        children: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3', 
          label: '3'
        }, {
          value: '4',
          label: '4'
        }, {
          value: '5',
          label: '5'
        }]
      }],
      // 工种类型
      typeList: [
        '数冲',
        '折弯',
        '钳铆'
      ],
      optionsRank: [
        {
        value: 'T0',
        label: 'T0',
        },
        {
        value: 'T1',
        label: 'T1',
        },
        {
        value: 'T2',
        label: 'T2',
        },
        {
        value: 'T3',
        label: 'T3',
        },
        {
        value: 'T4',
        label: 'T4',
        },
        {
        value: 'T5',
        label: 'T5',
        }
      ],
      sectionTypeObj: {
        emsOrz: [],
        cnc: ['数控一组','数控二组','铜排组','试制组','医疗产品组','职员组'],
        weld: ['人工焊组','机器人组','打磨组','职员组'],
        spray:['喷涂一线','喷涂二线','喷涂三线','样品线','前处理组','辅助组','职员组'],
        SheetMetal:['装配一线','装配二线','装配三线','装配四线','装配五线','装配六线','装配七线','装配八线','装配九线','包装组','组件一线','组件二线','组件三线','附件组','职员组'],
      },
      sectionTypeList: [],
      // 所有部门树选项
      deptOptions: [],
      // 过滤掉已禁用部门树选项
      enabledDeptOptions: [],
      // 有组级的部门
      isNeedList: ['EMS总装车间','装配车间','数控车间','焊接车间','结构总装车间','总装车间','销售服务部','研发部','喷涂车间','钣金装配','QC部','钣金工程部','钣金工艺部','新产品验证部','电装QC部','EMS车间','电装工艺部',
      '华海车间','物流部','PMC部','质量管理部','人力资源部','财务部'],
      marketList:['合同管理部','深圳销售一部','销售二部1组','销售二部2组','销售二部3组'],
      researchList:['深圳研发中心','从化研发中心'],
      QCList:['IPQC组','FQC组','职员组'],
      sheetMetal:['工程组','编程组'],
      metalProcess:['制程工艺组','装配工艺组'],
      productVerification:['NPI组','制程工艺组','职员组'],
      electricQC:['华海质量部','MES质量部','职员组'],
      technology:['华海工艺部','MES工艺部','职员组'],
      MESplant:['整机一线','整机二线','整机三线','插框线','包装线','充电桩专线','职员组'],
      HHplant:['整机线','插框线','附件组','包装组','职员组'],
      logistics:['ZA华为组','ZA发货组','木工组','原材料组','ZB共管组','ZB原材料组'],
      PMC:['计划组','物控组'],
      qualityControl:['质量保证部','供应商质量部','流程体系部'],
      HR:['信息安全部','绩效薪酬部','行政安全部','招聘任职部','深圳招聘任职部'],
      finance:['从化财务组','深圳财务组'],
      jobTitleList:[{jobTitle:''}],
      roleOptions:[]
    }
 },
 created() {
    this.focusUserName()
    this.getDeptTree();
    this.getRoleInfo()
  },
//  在该生命周期函数内将表单的各项内容填入
  mounted() {
    console.log(this.$route.params)
    this.getItem = this.$route.params
    this.form.userId = this.getItem.userId
    this.form.username = this.getItem.userName
    this.form.workNum = this.getItem.jobNumber
    this.form.roleId = this.getItem.roleId
    this.form.shortNum = this.getItem.shortNumber
    this.form.phone = this.getItem.phone
    this.form.parentNumber = this.getItem.parentNumber
    this.form.entryTime = this.getItem.entryTime
    this.form.newEmployee = this.getItem.newEmployee ? '1' : '0'
    this.form.status = this.getItem.status ? '1' : '0'
    // this.form.jobClassStr = this.getItem.jobClass.split('-')
    this.form.imageUrl = this.getItem.imageUrl
    this.form.departmentName = this.getItem.departmentName
    this.form.sectionType = this.getItem.sectionType
    this.form.type = this.getItem.type == 0?'':
                      this.getItem.type == 1?'数冲':
                      this.getItem.type == 2?'折弯':
                      this.getItem.type == 3?'钳铆':'-'
    this.form.sectionNo = this.getItem.sectionNo
    this.form.mail = this.getItem.mail
    this.form.deptId = this.getItem.deptId          // 部门id 
    this.form.tutorUserName = this.getItem.tutorUserName
    this.form.tutorJobNumber = this.getItem.tutorJobNumber
    this.form.tutorJobNumber = this.getItem.tutorJobNumber
    if(this.getItem.userKnowledgePost){
      this.form.userKnowledgePostId = this.getItem.userKnowledgePost.id
      this.form.jobCategory = this.getItem.userKnowledgePost.jobCategory
      this.form.rankOfPosition = this.getItem.userKnowledgePost.rankOfPosition == 1? this.form.rankOfPosition = '试用级':
                           this.form.rankOfPosition = this.getItem.userKnowledgePost.rankOfPosition == 2?'初级':
                           this.form.rankOfPosition = this.getItem.userKnowledgePost.rankOfPosition == 3?'中级':
                           this.form.rankOfPosition = this.getItem.userKnowledgePost.rankOfPosition == 4?'高级':
                           this.form.rankOfPosition = this.getItem.userKnowledgePost.rankOfPosition == 5?'师傅级':''
      this.form.jobTitle = this.getItem.userKnowledgePost.jobTitle
      this.form.criticalProcessName = this.getItem.userKnowledgePost.criticalProcessName
    }
    // if(this.getItem.jobClass){ this.form.jobClassStr = this.getItem.jobClass.split('-') }
    if(this.getItem.skillRank){ this.form.skillRank = this.getItem.skillRank.split(',') }
    if(this.getItem.jobTitleList.length) {
      this.jobTitleList = this.getItem.jobTitleList
      this.jobTitleList.forEach(item =>{
        item.rankOfPosition == 1 ? item.rankOfPosition = '试用级' 
        :item.rankOfPosition == 2 ? item.rankOfPosition = '初级'
        :item.rankOfPosition == 3 ? item.rankOfPosition = '中级'
        :item.rankOfPosition == 4 ? item.rankOfPosition = '高级'
        :item.rankOfPosition == 5 ? item.rankOfPosition = '师傅级':''
      })
    } else{
      this.jobTitleList = [{jobTitle:''}]
    }
    if(this.getItem.systemRoles){
      this.form.roleIds = this.getItem.systemRoles.map(item =>{
        return item.roleId
      })
    }
    console.log( this.jobTitleList)
  },
  watch: {  
    form: {  
      handler(newVal, oldVal) {
      this.$set(this.form,'jobTitle',newVal.jobTitle)
      },  
      deep: true, // 开启深度监听  
      immediate: true // 如果需要立即触发一次监听器，可以设置为 true  
    }  
  },
  methods: {
     /** 查询部门下拉树结构 */
     async getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
        this.enabledDeptOptions = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)));
      });
      const res = await systemgetUser()
      console.log('res',res);
      this.roleOptions = res.data.roles;
    },
    // 过滤禁用的部门
    filterDisabledDept(deptList) {
      return deptList.filter(dept => {
        if (dept.disabled) {
          return false;
        }
        if (dept.children && dept.children.length) {
          dept.children = this.filterDisabledDept(dept.children);
        }
        return true;
      });
    },
    // 修改导师
    tutorChange(e){
        console.log(e)
        this.form.tutorJobNumber = e
      },
    async focusName(){
            let query = {page:1,limit:9999,status: 1}
            const {data} = await findUserListGroup(query)
            console.log(data)
            this.nameList = data
        },
    // 岗位改变
    changeJobTitle(e){
      const findItme = this.jobTitleList.find(item =>item.id == e)
      this.$set(this.form,'jobTitle',findItme.jobTitle)
      this.$set(this.form,'jobCategory',findItme.userJobCategory)
      this.$set(this.form,'userKnowledgePostId',findItme.id)
      console.log(this.form.jobTitle)
      // this.form.jobTitle = item.jobTitle
      // this.form.jobCategory = item.userJobCategory
      // this.form.userKnowledgePostId  = item.id
    },
    async modify() {
      await this.$refs.form.validate()
      if(!this.form.deptId) return this.$message.warning('请选择归属部门！')
      // 将当前输入的工号传递到后台系统，验证改工号是否已经被注册
      const data = await testWorkNum({ jobNumber: this.form.parentNumber, type: '1' })
      if(data.code != '1') return  this.$message({
            type: 'warning',
            message: '上级领导工号不存在！'
        })
      // if(this.form.departmentName == '数控车间' && !this.form.type) return  this.$message({
      //         type: 'warning',
      //         message: '请选择该员工工种类型'
      //   })
       let query = {
        mail:this.form.mail,
        departmentName: this.form.departmentName,
        userName: this.form.username,
        phone: this.form.phone == null ? '' : this.form.phone,
        jobNumber: this.form.workNum,
        roleId: this.form.roleId,
                // this.form.roleId == '超级管理员' ? '0' :
                // this.form.roleId == '工艺管理员' ? '1' :
                // this.form.roleId == '员工管理员' ? '2' :
                // this.form.roleId == 'QC质量检' ? '3' :
                // this.form.roleId == '装配计划人员' ? '4' :
                // this.form.roleId == 'EC首产检' ? '5' :
                // this.form.roleId == 'FC非标检' ? '6' :
                // this.form.roleId == 'QE' ? '7' :
                // this.form.roleId == '普通员工' ? '8' :
                // this.form.roleId == '工段长' ? '9' :
                // this.form.roleId == '试水' ? '10' :
                // this.form.roleId == '试水检测' ? '11' :
                // this.form.roleId == '总监' ? '12' :
                // this.form.roleId == '车间主任' ? '15' :
                // this.form.roleId == 'PMC' ? '16' :
                // this.form.roleId == '生产' ? '19' :
                // this.form.roleId == '质量文员' ? '23' :
                // this.form.roleId == '质量总监' ? '24' :
                // this.form.roleId == '数控机台调度员' ? '25' :
                // this.form.roleId == '包装工段长权限' ? '26' :
                // this.form.roleId == '工艺经理' ? '27' :
                // this.form.roleId == '设备人员' ? '28' :
                // this.form.roleId == '计划总监' ? '29' :
                // this.form.roleId == '工艺总监' ? '30' :
                // this.form.roleId == '物流人员' ? '31' :
                // this.form.roleId == '数控计划人员' ? '32' :
                // this.form.roleId == 'EMS车间QC' ? '33' :
                // this.form.roleId == 'EMS车间OBA' ? '34' :
                // this.form.roleId == '工艺管理员(EMS)' ? '35' :
                // this.form.roleId == '工艺经理(EMS)' ? '36' :
                // this.form.roleId == '老板' ? '37' :
                // this.form.roleId == '焊接机台调度员' ? '38' :
                // this.form.roleId == '车间文员（人员管理）' ? '39' :
                // this.form.roleId == '木工' ? '40' :
                // this.form.roleId == '喷涂机台调度员' ? '41' :
                // this.form.roleId == '喷涂计划人员' ? '42' :
                // this.form.roleId == '医疗车间调度员' ? '43' :  '-',

        entryTime: this.form.entryTime,
        status: this.form.status,
        newEmployee: this.form.newEmployee,
        parentNumber: this.form.parentNumber,
        imageUrl: this.form.imageUrl,
        sectionNo: this.form.sectionNo?this.form.sectionNo:'',
        // jobClassStr: this.form.jobClassStr.join('-'),
        shortNumber: this.form.shortNum == null ? '' : this.form.shortNum,
        sectionType: this.form.sectionType,
        tutorJobNumber: this.form.tutorJobNumber ? this.form.tutorJobNumber : '',
        userKnowledgePostId: this.form.userKnowledgePostId ? this.form.userKnowledgePostId : '',
        deptId: this.form.deptId ? this.form.deptId : '',
        roleIds: this.form.roleIds,
        userId: this.form.userId
      }
      if(!query.mail){
        delete query.mail
      }
      console.log('query',query)
      // if(this.form.departmentName == '数控车间'){
      //     query.type = this.form.type == '数冲'?1:
      //                  this.form.type == '折弯'?2:
      //                  this.form.type == '钳铆'?3:0
      // } else {
      //     query.type = 0
      // }
      if(!query.sectionType) { delete query.sectionType }
      console.log(this.form)
      if(this.form.skillRank && this.form.skillRank.length){ query.skillRank = this.form.skillRank.toString() }
      try{
        const data = await modifyWorkers(query)
        if(data.code == 500) return
        if(data.code == '1'){
             this.$message({
             message: '修改成功',
             type: 'success'
             })
          } else {
             this.$message({
             message: data.msg,
             type: 'warning'
             })
          }
      }catch(e){}
    },
    isNeedget(val){
      return this.isNeedList.some(item => item == val.trim())
    },
    getsectionType(){
      if(this.form.departmentName.trim() == 'EMS总装车间' || this.form.departmentName.trim() == '装配车间' || this.form.departmentName.trim() == '总装车间' || this.form.departmentName.trim() == '结构总装车间') {
        let workCenter = this.form.departmentName.trim() == '结构总装车间'?'总装车间':this.form.departmentName.trim()
        this.getworkSection(workCenter)
      } else if(this.form.departmentName.trim() == '数控车间') {
        this.sectionTypeList = this.sectionTypeObj.cnc
      } else if(this.form.departmentName.trim() == '焊接车间') {
        this.sectionTypeList = this.sectionTypeObj.weld
      } else if(this.form.departmentName.trim() == '喷涂车间') {
        this.sectionTypeList = this.sectionTypeObj.spray
      } else if(this.form.departmentName.trim() == '钣金装配') {
        this.sectionTypeList = this.sectionTypeObj.SheetMetal
      } else if(this.form.departmentName.trim() == '销售服务部') {
        this.sectionTypeList = this.marketList
      } else if(this.form.departmentName.trim() == '研发部') {
        this.sectionTypeList = this.researchList
      } else if(this.form.departmentName.trim() == 'QC部') {
        this.sectionTypeList = this.QCList
      } else if(this.form.departmentName.trim() == '钣金工程部') {
        this.sectionTypeList = this.sheetMetal
      } else if(this.form.departmentName.trim() == '钣金工艺部') {
        this.sectionTypeList = this.metalProcess
      } else if(this.form.departmentName.trim() == '新产品验证部') {
        this.sectionTypeList = this.productVerification
      } else if(this.form.departmentName.trim() == '电装QC部') {
        this.sectionTypeList = this.electricQC
      } else if(this.form.departmentName.trim() == 'EMS车间') {
        this.sectionTypeList = this.MESplant
      } else if(this.form.departmentName.trim() == '电装工艺部') {
        this.sectionTypeList = this.technology
      } else if(this.form.departmentName.trim() == '华海车间') {
        this.sectionTypeList = this.HHplant
      } else if(this.form.departmentName.trim() == '物流部') {
        this.sectionTypeList = this.logistics
      } else if(this.form.departmentName.trim() == 'PMC部') {
        this.sectionTypeList = this.PMC
      } else if(this.form.departmentName.trim() == '质量管理部') {
        this.sectionTypeList = this.qualityControl
      } else if(this.form.departmentName.trim() == '人力资源部') {
        this.sectionTypeList = this.HR
      } else if(this.form.departmentName.trim() == '财务部') {
        this.sectionTypeList = this.finance
      }
    },
    async getworkSection(val){
      let midsectionTypeList = []
      const { data } = await checkWorkSecInfo({workCenter: val,page: 1,limit: 10000})
      data.records.forEach(item => {
        if(item.status && item.sectionAbbreviation){ midsectionTypeList.push(item.sectionAbbreviation) }
      });
      if(!midsectionTypeList.length) return this.sectionTypeList = []
      let set = new Set(midsectionTypeList)
      this.sectionTypeList = Array.from(set)
      this.sectionTypeList.push('附件组')
    },
    changesectionType(e){
      this.$set(this.form, 'sectionType', '')
    },
    // 将当前输入的工号传递到后台系统，验证改工号是否已经被注册
    async testExist() {
      const { data } = await testWorkNum({ jobNumber: this.form.workNum })
    },
    // 将当前输入的工号传递到后台系统，验证改工号是否已经被注册
    async testExist2() {
      const data = await testWorkNum({ jobNumber: this.form.parentNumber, type: '1' })
      if(data.code == '1'){
          this.$message({
            type: 'success',
            message: '工号验证通过'
          })
      } else {
          this.$message({
            type: 'warning',
            message: data.msg
        })
      }
    },
    // 获取角色列表函数
    async getRoleInfo() {
      try {
        this.roleList = await getRoleList()
      } catch (err) {}
    },
    // 获取部门函数
    async getDepartInfo() {
     try {
        this.departList = await getDepartList()
      } catch (err) {}
    },
    // "取消"按钮
    onCancel() {
      console.log('bye')
    },
    // 用户头像上传成功之后的触发函数
    handleAvatarSuccess(res,file) {
      this.form.imageUrl = res.results
        this.$message({
          message: '用户图像上传成功',
          type: 'success'
        })
    },
    // 用户头像上传之前判断函数，格式限制为JPG，大小小于2M
    // const声明一个只读的常量。一旦声明，常量的值就不能改变。且只在声明所在的块级作用域内有效
    beforeAvatarUpload(file) {
      this.upPictureData.jobNumber = this.form.workNum
      this.upPictureData.file = file + Math.random()
      // console.log(this.form.workNum,file)
      // const isJPG = file.type === 'image/jpeg'
      // const isLt2M = file.size / 1024 / 1024 < 2
      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG 格式!')
      // }
      // if (!isLt2M) {
      //   this.$message.error('上传头像图片大小不能超过 2MB!')
      // }
      // return isJPG && isLt2M;
    }
  }
}
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
